class Edges:
    def __init__(self, puzzle):
        self.puzzle = puzzle
        self.lines = []
        for i in range(81):
            line = self.puzzle.canvas.create_line(
                0,
                0,
                0,
                0,
                fill="black",
                width=2,
                smooth=True,
                state="hidden",
            )
            self.lines.append(line)
        self.current_index = 0

    def drawEdgebyCands(self, row1, col1, cand1, row2, col2, cand2, color="black"):
        x1, y1 = self.getPostion(row1, col1, cand1)
        x2, y2 = self.getPostion(row2, col2, cand2)
        line = self.lines[self.current_index]
        self.current_index += 1
        self.puzzle.canvas.coords(line, x1, y1, x2, y2)
        self.puzzle.canvas.itemconfigure(line, state="normal", fill=color)

    def drawEdge(self, *args, **kw):
        line = self.lines[self.current_index]
        self.current_index += 1
        self.puzzle.canvas.coords(line, *args)
        self.puzzle.canvas.itemconfigure(line, state="normal", **kw)

    def getPostion(self, rowNum, colNum, cand):
        cell = self.puzzle.baseCells[rowNum][colNum]
        cand -= 1
        x = cell.x0 + (cand % 3 + 0.5) * cell.cellSize / 3
        y = cell.y0 + (cand // 3 + 0.5) * cell.cellSize / 3
        return x, y

    def clearup(self):
        for line in self.lines[self.current_index]:
            self.puzzle.canvas.itemconfigure(line, state="hidden")
        self.current_index = 0
